package com.igoal.campaign.dto;

import java.util.Date;

import com.igoal.campaign.entity.Campaign;
import com.igoal.dto.BaseDTO;
import com.igoal.utils.CalendarUtils;
import com.igoal.utils.SynchronizeAttributeWithOther;
import com.igoal.utils.SynchronizeDirection;

public class CampaignDTO extends BaseDTO<Campaign> {

	private String campainName;
	private String url;
	private Date from;
	private String fromDate;
	private Date to;
	private String toDate;
	private boolean usedUserDB;
	private boolean usedMarketingDB;
	private String emailTitleTemplate;
	private String emailBodyTemplate;
	
	public String getCampainName() {
		return campainName;
	}
	public void setCampainName(String campainName) {
		this.campainName = campainName;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public Date getFrom() {
		return from;
	}
	public void setFrom(Date from) {
		this.from = from;
	}
	public Date getTo() {
		return to;
	}
	public void setTo(Date to) {
		this.to = to;
	}
	public boolean isUsedUserDB() {
		return usedUserDB;
	}
	public void setUsedUserDB(boolean usedUserDB) {
		this.usedUserDB = usedUserDB;
	}
	public boolean isUsedMarketingDB() {
		return usedMarketingDB;
	}
	public void setUsedMarketingDB(boolean usedMarketingDB) {
		this.usedMarketingDB = usedMarketingDB;
	}
	public String getEmailTitleTemplate() {
		return emailTitleTemplate;
	}
	public void setEmailTitleTemplate(String emailTitleTemplate) {
		this.emailTitleTemplate = emailTitleTemplate;
	}
	public String getEmailBodyTemplate() {
		return emailBodyTemplate;
	}
	public void setEmailBodyTemplate(String emailBodyTemplate) {
		this.emailBodyTemplate = emailBodyTemplate;
	}
	public String getFromDate() {
		return fromDate;
	}
	public void setFromDate(String fromDate) {
		this.fromDate = fromDate;
	}
	public String getToDate() {
		return toDate;
	}
	public void setToDate(String toDate) {
		this.toDate = toDate;
	}
	
	@SynchronizeAttributeWithOther(direction=SynchronizeDirection.FROM, value="from")
	public void initFromDate(Object entity){
		if(entity != null && entity instanceof Date){
			Date d = (Date) entity;
			fromDate = CalendarUtils.formatDate(d, CalendarUtils.DD_MM_YYYY);
		}
	}
	
	@SynchronizeAttributeWithOther(direction=SynchronizeDirection.FROM, value="to")
	public void initToDate(Object entity){
		if(entity != null && entity instanceof Date){
			Date d = (Date) entity;
			toDate = CalendarUtils.formatDate(d, CalendarUtils.DD_MM_YYYY);
		}
	}
	
	@SynchronizeAttributeWithOther(direction=SynchronizeDirection.TO, value="from")
	public Date convertFromDate(){
		Date d = CalendarUtils.parseDate(fromDate, CalendarUtils.DD_MM_YYYY);		
		return d;
	}
	
	@SynchronizeAttributeWithOther(direction=SynchronizeDirection.TO, value="to")
	public Date convertToDate(){
		Date d = CalendarUtils.parseDate(toDate, CalendarUtils.DD_MM_YYYY);		
		return d;
	}
}
